package com.example.config;

import com.example.enums.BizCodeEnum;
import com.example.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author yinxin
 * @version 1.0
 * @Description:
 * @date 2022/6/811:24
 */
@Configuration
@Slf4j
public class SnowFlakeWordIdConfig {

    static {
        try {
            InetAddress localHost = Inet4Address.getLocalHost();
            String hostAddressIp = localHost.getHostAddress();
            String workId = Math.abs(hostAddressIp.hashCode()) % 1024 + "";
            System.setProperty("workId",workId);
            log.info("workId是{}",workId);
        } catch (UnknownHostException e) {
            throw new BizException(BizCodeEnum.OPS_NETWORK_ADDRESS_ERROR);
        }

    }

}
